package com.fc.redap.dtos;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@SuppressWarnings("unchecked")
public class ResponseJson<T> {
    public static final int SUCCESS_200 = 200;
    public static final int BAD_REQUEST = 400;
    public static final int UNAUTHORIZED = 401;
    public static final int NOT_FOUND = 404;
    public static final int CODE_403 = 403;
    public static final int TOKEN_TIMEOUT = 408;
    public static final int CODE_500 = 500;

    private boolean success = true;// 是否成功
    private Integer code = 200;
    private String msg = "";
    private T response;

    public ResponseJson() {
        this.success = true;
    }

    private ResponseJson(boolean success, String msg, Integer code, T response ) {
        this.success = success;
        this.msg = msg;
        this.response = response;
        this.code = code;
    }

    public static ResponseJson error(Integer code, String message)
    {
        return new ResponseJson(false, message, code, null);
    }

    public static ResponseJson error(String message)
    {
        return new ResponseJson(false, message, CODE_500, null);
    }

    public static ResponseJson success()
    {
        return new ResponseJson(true, null, SUCCESS_200, null);
    }

    public static ResponseJson success(Object response)
    {
        return new ResponseJson(true, null, SUCCESS_200, response);
    }
}
